package com.example.cstr.service.serviceImpl;

import com.example.cstr.entity.EducationTrainClass;
import com.example.cstr.entity.Message;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.example.cstr.entity.Announcement;
import com.example.cstr.mapper.AnnouncementMapper;
import com.example.cstr.service.AnnouncementService;

import java.util.List;

@Service
public class AnnouncementServiceImpl implements AnnouncementService {

    @Resource
    private AnnouncementMapper announcementMapper;

    @Override
    public int deleteByPrimaryKey(Integer ancId) {
        return announcementMapper.deleteByPrimaryKey(ancId);
    }

    @Override
    public int insert(Announcement record) {
        return announcementMapper.insert(record);
    }

    @Override
    public int insertSelective(Announcement record) {
        if (record.getAncStatus() == null) {
            record.setAncStatus(0);
        }
        return announcementMapper.insertSelective(record);
    }

    @Override
    public Announcement selectByPrimaryKey(Integer ancId) {
        return announcementMapper.selectByPrimaryKey(ancId);
    }

    @Override
    public int updateByPrimaryKeySelective(Announcement record) {
        return announcementMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Announcement record) {
        return announcementMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<Announcement> selectAllAnnouncement() {
        return announcementMapper.selectAllByAncStatus(1);
    }

    @Override
    public Message PagingSearch(Integer pageNum, Integer size) {
        PageHelper.startPage(pageNum, size);
        List<Announcement> announcementList = announcementMapper.selectAllByAncStatus(1);
        PageInfo pageInfo = new PageInfo(announcementList);
        pageInfo.getTotal();
        return Message.success(null).add(pageInfo);
    }

}


